<template>
  <el-container>
    <!-- aside侧边栏 -->
    <el-aside width="200">
      <h1 class="logo"></h1>
      <el-menu :collapse="collapse" class="el-qf-menu" :default-active="$route.path">
        <qf-sub-menu :sideMenu="sideMenu"></qf-sub-menu>
      </el-menu>
    </el-aside>
    <el-container>
      <!-- header顶部栏 -->
      <el-header>
        <el-row type="flex" class="row-bg" justify="space-between">
          <el-col :span="6">
            <div class="grid-content left">
              <i @click="collapse=!collapse" :class="['iconfont',collapse?'icon-zhankai':'icon-shouqi']"></i>
            </div>
          </el-col>
          <el-col :span="6"><div class="grid-content center">CRM管理系统</div></el-col>
          <el-col :span="6">
            <div class="grid-content right">
              <el-avatar shape="square" size="large" :src="squareUrl"></el-avatar>
              <b>欢迎您:
                <el-dropdown @command="command">
                  <span class="nickname">
                    {{userInfo.nickname}}
                    <i class="iconfont icon-xiala"></i>
                  </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item command="charge" icon="iconfont icon-VIPchongzhi-">vip充值</el-dropdown-item>
                    <el-dropdown-item command="mine" icon="iconfont icon-zhanghaoxinxi">账号信息</el-dropdown-item>
                    <el-dropdown-item command="product" icon="iconfont icon-xiangmuguanli">项目管理</el-dropdown-item>
                    <el-dropdown-item icon="iconfont icon-tuichu" @click.native="quit">退出</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </b>
              &nbsp;
              <!-- <b class="quit" @click="quit">退出</b> -->
            </div>
          </el-col>
        </el-row>
      </el-header>
      <!-- main主体部分 -->
      <el-main>
        <!-- 面包屑 -->
        <el-breadcrumb separator="/">
					<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
					<el-breadcrumb-item :to="{ name: bread.name }"
						v-for="bread in breadCrumb"
						:key="bread.name">
						{{ bread.meta.name }}
					</el-breadcrumb-item>
				</el-breadcrumb>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import * as api from "../../api";
import {mapState} from "vuex";
export default {
  computed:{
    ...mapState(["userInfo","sideMenu","breadCrumb"]),
    squareUrl(){//如果用户没有头像就使用默认头像
       return this.userInfo.headimgurl?this.userInfo.headimgurl:"https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png"

    }


  },
  mounted(){
    // api.getLoginLogApi()
    // .then(res=>{
    //   console.log(res.data);
    // })
  },
  data() {
    return {
      collapse:false
      
    };
  },
  methods:{
    //右上方用户下拉菜单触发事件
    command(routerName){
      //routerName就是下拉菜单传入的路由名字
      if(routerName){
        this.$router.push({name:routerName})
      }

    },
    quit(){
      //1.清除token
      localStorage.removeItem("qf-token")
      //2.退出回到登录页
      this.$router.push("/login")
      //3.刷新页面
      location.reload()
    }
  }
};
</script>
<style scoped lang="less">
.el-header {
  background: linear-gradient(135deg, #4c67ff, #5635df);
  color: #fff;
  text-align: center;
  font-weight: 500;
  .left {
    text-align: left;
    i {
      font-size: 40px;
      cursor: pointer;
    }
  }
  .center {
    font-size: 20px;
    padding-top: 8px;
  }
  .right {
    b {
      padding-left: 10px;
      .nickname{
        color:deepskyblue;
        cursor:pointer;
        margin-left:5px;
      }
    }
    .quit{
      color:red;
      text-decoration:underline;
      cursor:pointer;
    }
    .el-avatar {
      vertical-align: middle;
    }
  }
  //line-height: 60px; 行高会继承，影响操作
}

.el-aside {
  background: linear-gradient(135deg, #4c67ff, #5635df);
  color: #333;
  text-align: center;
  //line-height: 200px;
  .logo {
    min-height: 60px;
    background:deepblue;
    background-image: url(http://chst.vip:8081/stu2/img/logo.be8bbddf.png);
    background-size: 80%;
    background-repeat: no-repeat;
    background-position-y: center;
    background-position-x: 40%;
  }
  .subMenu{
    text-align:left;
  }
  /deep/ .el-qf-menu:not(.el-menu--collapse) {
		width: 200px;
		min-height: 400px;
	}
}

.el-main {
  background-color: #fff;
  color: #333;
  text-align: center;
  //line-height: 160px;
}

.el-container {
  margin-bottom: 40px;
  height: 100%;
}


// 顶部栏布局
.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
}
</style>
